<template>
  <!-- 系统账单管理 -->
  <div class="all">
    <div class="header">
      <!-- 时间选择 -->
    <el-date-picker
      v-model="value2"
      type="datetimerange"
      :picker-options="pickerOptions"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      align="right">
    </el-date-picker> 
      <!-- 交易类型选择 -->
      <el-select v-model="type" clearable placeholder="请选择交易类型">
        <el-option label="充值" value="充值" />
        <el-option label="收益" value="收益" />
        <el-option label="提现" value="提现" />
      </el-select>
      <!-- 交易状态选择 -->
       <!-- 产品状态下拉框 -->
      <el-select v-model="status" clearable placeholder="请选择状态">
        <el-option label="正常" value="正常" />
        <el-option label="未审核" value="未审核" />
      </el-select>
      <!-- 顾客编号选择 -->

      <!-- 查询 -->
       <el-button type="primary" @click="querysystem()" >查询</el-button>
    </div>
    <div class="content">
      <!-- 表格内容 -->
      <el-table :data="customerData" style="width: 100%">
        <el-table-column prop="id" label="编号" width="180" />
        <el-table-column prop="transferMoney" label="交易金额" width="180" />
        <el-table-column prop="transferTime" label="交易时间">
          <template slot-scope="scope">
            {{ scope.row.transferTime | fmtDate }}
          </template>
        </el-table-column>
         <el-table-column prop="type" label="交易类型" width="180" />
        <el-table-column prop="status" label="交易状态">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status == '正常' ? 'success' : 'warning'">{{
              scope.row.status
            }}</el-tag>
          </template>
        </el-table-column>
         <el-table-column prop = "description" label="描述">
        </el-table-column>
        </el-table>
    </div>
    
    <!-- 分页组件 -->
    <div class="paginetion">
      <!-- 分页组件 -->
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { get, post } from '@/utils/request'
export default {
  data() {
    return {
      customerData:[],
       currentPage: 1,
      // 每页要展示的数据条数
      pageSize: 6,
      // 页面展示数据的总条数
      total:10,
      //存放顾客编号
      customerId1:'',
      customerId2:'',
      //类型
      type:'',
      //状态
      status:'',
      queryData:{},
       pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value2: '',
        time1:'',
        time2:''
    }
  },
  computed: {},
  methods: {
    //查询顾客编号
     async FindcustomerId(){
      let data = {
        page:1,
        pageSize:1000,
        roleId:6
      }
      let res = await get ('/baseUser/pageQuery',{...data})
      this.customerId1 = res.data.list
    },
    //查询顾客所有数据
    async getAllcustomer(){
      let data = {
        page:this.currentPage,
        pageSize:this.pageSize
      }
      let res = await get('/account/pageQuerySystemAccount',{...data,...this.queryData})
      this.customerData = res.data.list
      //修改页面数据
      this.total = res.data.total
    },
    //分页查询
    handleSizeChange(val) {
      // 将每页要展示的数据的条数 进行一个更新
      this.pageSize = val
      // 将当前的页数 重置到第一页
      this.currentPage = 1
      // 重新调用获取所有产品数据的方法
      this.getAllcustomer()
    },
    handleCurrentChange(val) {
      // 将当前页数 与 分页插件动态点击控制的页数相绑定
      this.currentPage = val
      // 重新调用获取所有产品数据的方法
      this.getAllcustomer()
    },
    //查找
    querysystem() {
      this.changetime()
      let data = {
        // 状态关键字
        status: this.status,
        // 类型
        type: this.type,
        // 顾客编号
        userId: this.customerId2,
        //开始时间
        beginTime:this.time1,
        //结束时间
        endTime:this.time2
      }
      // 格式化参数 当某个属性没有值的时候 将其删除掉 以防影响网络请求的操作
      for (let key in data) {
        if (!data[key]) {
          delete data[key]
        }
      }
      // 将参数 赋值给 queryData
      this.queryData = data
      // 将页数强制回到第一页
      this.currentPage = 1
      // 重新加载产品数据
      this.getAllcustomer()
       this.time1 = null
      this.time2 =null
    },
    //转换时间
    changetime(){
      //将时间转换为林威治时间数值
      if(this.value2 != null){
        this.time2 = new Date(this.value2[1]).getTime();
      this.time1 = new Date(this.value2[0]).getTime();
      }
    }
  },
  created() {
    this.getAllcustomer()
    this.FindcustomerId()
  },
  mounted() {},
};
</script>
<style scoped>
</style>


